package com.eastcom.notice;

import java.util.List;

public class MessageFactory
{
  public List<NoticeMessage> aliveSocket;
  public static MessageFactory factory;

  private MessageFactory(List<NoticeMessage> aliveSocket)
  {
    this.aliveSocket = aliveSocket;
  }

  private void sendMessage(String xml) {
    if ((this.aliveSocket != null) && (this.aliveSocket.size() > 0))
      for (NoticeMessage mess : this.aliveSocket)
        mess.sendMessage(xml);
  }

  public static void init(List<NoticeMessage> aliveSocket)
  {
    if (factory == null)
      factory = new MessageFactory(aliveSocket);
  }

  public static void addObject(Object o, String uuid) {
    factory.sendMessage("1:" + o.getClass().getName() + ":" + uuid); }

  public static void delObject(Object o, String uuid) {
    factory.sendMessage("2:" + o.getClass().getName() + ":" + uuid); }

  public static void updateObject(Object o, String uuid) {
    factory.sendMessage("3:" + o.getClass().getName() + ":" + uuid);
  }
}